<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改基本设置')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-baseconfig-edit" th:object="${whzjBaseconfig}">
            <input id="id" name="id" th:field="*{id}" type="hidden">
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">自动升级代理的邀请人数：</label>
                    <div class="col-sm-9">
                        <input id="autoRiselevel" name="autoRiselevel" th:field="*{autoRiselevel}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">一级代理商分成：</label>
                    <div class="col-sm-9">
                        <input id="firstDistrirate" name="firstDistrirate" th:field="*{firstDistrirate}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">二级代理商分成：</label>
                    <div class="col-sm-9">
                        <input id="secondDistirrate" name="secondDistirrate" th:field="*{secondDistirrate}" class="form-control" type="text">
                    </div>
                </div>
                <!--<div class="form-group">
                    <label class="col-sm-3 control-label">免费升级vip邀请注册人数：</label>
                    <div class="col-sm-9">
                        <input id="freeVip" name="freeVip" th:field="*{freeVip}" class="form-control" type="text">
                    </div>
                </div>-->
                <div class="form-group">
                    <label class="col-sm-3 control-label">分享赠送积分：</label>
                    <div class="col-sm-9">
                        <input id="shareSend" name="shareSend" th:field="*{shareSend}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <!--<div class="form-group">
                    <label class="col-sm-3 control-label">最小提现金额整数倍：</label>
                    <div class="col-sm-9">
                        <input id="minWithdraw" name="minWithdraw" th:field="*{minWithdraw}" class="form-control" type="text">
                    </div>
                </div>-->
                <div class="form-group">
                    <label class="col-sm-3 control-label">首次登陆赠送积分：</label>
                    <div class="col-sm-9">
                        <input id="firstSend" name="firstSend" th:field="*{firstSend}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">客服QQ号：</label>
                    <div class="col-sm-9">
                        <input id="serviceQq" name="serviceQq" th:field="*{serviceQq}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">每日签到赠送积分：</label>
                    <div class="col-sm-9">
                        <input id="dailySend" name="dailySend" th:field="*{dailySend}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">绑定手机号赠送积分：</label>
                    <div class="col-sm-9">
                        <input id="relatePhone" name="relatePhone" th:field="*{relatePhone}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">免费领取积分：</label>
                    <div class="col-sm-9">
                        <input id="freeIntegral" name="freeIntegral" th:field="*{freeIntegral}" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">活动最多参与次数：</label>
                    <div class="col-sm-9">
                        <textarea id="activitynum" name="agentDesc" maxlength="500" class="form-control" rows="3" th:field="*{activitynum}" ></textarea>
                    </div>
                </div>
            </div>
            <!--<div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">代理描述：</label>
                    <div class="col-sm-9">
                        <textarea id="agentDesc" name="agentDesc" maxlength="500" class="form-control" rows="3" th:field="*{agentDesc}" ></textarea>
                    </div>
                </div>
            </div>-->
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">加入代理需要支付的金额：</label>
                    <div class="col-sm-9">
                        <input id="agentPay" name="agentPay" class="form-control" type="text" th:field="*{agentPay}" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">代理加入方式：</label>
                    <div class="col-sm-9">
                        <textarea id="agentMethod" name="agentMethod" maxlength="500" class="form-control" rows="3" th:field="*{agentMethod}" ></textarea>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">代理加入优势：</label>
                    <div class="col-sm-9">
                        <textarea id="agentGoods" name="agentGoods" maxlength="500" class="form-control" rows="3" th:field="*{agentGoods}" ></textarea>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">分享页面标题：</label>
                    <div class="col-sm-9">
                        <input id="shareTitle" name="shareTitle" th:field="*{shareTitle}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">分享页面内容：</label>
                    <div class="col-sm-9">
                        <textarea id="shareContent" name="shareContent" maxlength="500" class="form-control" rows="3" th:field="*{shareContent}"></textarea>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <div class="form-group">
                    <label class="col-sm-3 control-label">分享页面图片：</label>
                    <div class="col-sm-9">
                        <input id="sharePicUrl" type="hidden" name="sharePic" th:field="*{sharePic}">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="sharePic" name="file" type="file">
                        </div>
                    </div>
                </div>
                <div class="form-group">
                   <label class="col-sm-3 control-label"></label>
                    <div class="col-sm-9">
                    </div>
                </div>
            </div>
               <!-- <div class="form-group">
                    <label style="text-align: left;margin-right:50%;" class="col-sm-3 control-label">分享页面图片：</label>
                </div>
                <div class="form-group">
                    <div class="col-sm-9">
                        <input id="sharePicUrl" type="hidden" name="sharePic" th:field="*{sharePic}">
                        <div class="file-loading">
                            <input class="form-control file-upload" id="sharePic" name="file" type="file">
                        </div>
                    </div>
                </div>-->
           <!-- <div class="col-md-6">
                <button style="float: left" type="button" class="btn btn-success" onclick="saveSetting();">提交</button>
            </div>-->
        </form>
    </div>
    <div>
        <button style="text-align: center;margin-top: 400px;" type="button" class="btn btn-success" onclick="saveSetting();">提交</button>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "whzj/baseconfig";
        $("#form-baseconfig-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-baseconfig-edit').serialize());
            }
        }

        $(function() {
            $('.summernote').each(function(i) {
                $('#' + this.id).summernote({
                    lang: 'zh-CN',
                    callbacks: {
                        onChange: function(contents, $edittable) {
                            $("input[name='" + this.id + "']").val(contents);
                        },
                        onImageUpload: function(files) {
                            var obj = this;
                            var data = new FormData();
                            data.append("file", files[0]);
                            $.ajax({
                                type: "post",
                                url: ctx + "common/upload",
                                data: data,
                                cache: false,
                                contentType: false,
                                processData: false,
                                dataType: 'json',
                                success: function(result) {
                                    if (result.code == web_status.SUCCESS) {
                                        $('#' + obj.id).summernote('insertImage', result.url);
                                    } else {
                                        $.modal.alertError(result.msg);
                                    }
                                },
                                error: function(error) {
                                    $.modal.alertWarning("图片上传失败。");
                                }
                            });
                        }
                    }
                });
                var content = $("input[name='" + this.id + "']").val();
                $('#' + this.id).summernote('code', content);
            })
        });


        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': '/common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        function saveSetting() {
            /*if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-tasksetting-edit').serialize());
            }*/
            var formData = new FormData();
            formData.append('id',$("#id").val());
            formData.append('autoRiselevel',$("#autoRiselevel").val());
            formData.append('firstDistrirate',$("#firstDistrirate").val());
            formData.append('secondDistirrate',$("#secondDistirrate").val());
            /*formData.append('freeVip',$("#freeVip").val());*/
            formData.append('shareSend',$("#shareSend").val());
            /*formData.append('minWithdraw',$("#minWithdraw").val());*/
            formData.append('firstSend',$("#firstSend").val());
            formData.append('serviceQq',$("#serviceQq").val());
            formData.append('serviceWx',$("#serviceWx").val());
            /*formData.append('agentDesc',$("#agentDesc").val());*/
            formData.append('dailySend',$("#dailySend").val());
            formData.append('freeIntegral',$("#freeIntegral").val());
            formData.append('shareTitle',$("#shareTitle").val());
            formData.append('shareContent',$("#shareContent").val());
            formData.append('sharePic',$("#sharePicUrl").val());
            formData.append('relatePhone',$("#relatePhone").val());
            formData.append('agentMethod',$("#agentMethod").val());
            formData.append('agentGoods',$("#agentGoods").val());
            formData.append('activitynum',$("#activitynum").val());
            formData.append('agentPay',$("#agentPay").val());
            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    $.operate.successCallback(result);
                }
            });
        }
    </script>


</body>
</html>